package cn.santi.controller;

import cn.santi.domain.ABoxMeal;
import cn.santi.domain.ACoupon;
import cn.santi.emuns.R;
import cn.santi.service.ABoxMealService;
import cn.santi.service.ACouponService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/Coupon")
public class CouponController {

    @Autowired
    private ACouponService couponService;

    @Autowired
    private ABoxMealService bomMealService;

    @RequestMapping("/getABoxMealByBid")
    public R getABoxMealByBid(Integer bid){//根据门店id查询套餐
        LambdaQueryWrapper<ABoxMeal> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ABoxMeal::getBid, bid).orderByAsc(ABoxMeal::getPrice);
        List<ABoxMeal> list = bomMealService.list(wrapper);
        return R.ok(list);
    }

    @GetMapping("/getCouponByBid")
    public R getCouponByBid(Integer bid) {//根据门店id查询团购券
        LambdaQueryWrapper<ACoupon> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ACoupon::getBid, bid).orderByDesc(ACoupon::getVal);
        List<ACoupon> list = couponService.list(wrapper);
        return R.ok(list);
    }
}
